package com.jyw.business.ins.service.impl;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.jyw.business.ins.domain.vo.web.InsTaskItemVO;
import com.jyw.business.ins.domain.vo.web.TaskItemVo;
import com.jyw.system.utils.ConversionUtil;
import org.springframework.stereotype.Service;
import com.jyw.business.ins.mapper.InsTaskItemMapper;
import com.jyw.business.ins.domain.InsTaskItem;
import com.jyw.business.ins.service.IInsTaskItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 巡检任务巡检项Service业务层处理
 *
 * @author system
 * @date 2023-10-07
 */
@Service
public class InsTaskItemServiceImpl extends ServiceImpl<InsTaskItemMapper,InsTaskItem> implements IInsTaskItemService
{
    @Resource
    private InsTaskItemMapper insTaskItemMapper;


    /**
     * 修改巡检任务巡检项
     *
     * @param insTaskItem 巡检任务巡检项
     * @return 结果
     */
    @Override
    public int updateInsTaskItem(InsTaskItem insTaskItem)
    {
        return insTaskItemMapper.updateInsTaskItem(insTaskItem);
    }

    @Override
    public List<InsTaskItemVO> findListByTaskId(Long taskId) {
        List<InsTaskItemVO> list = insTaskItemMapper.findListByTaskId(taskId);
        if(CollectionUtil.isNotEmpty(list)){
            list.forEach(item->{
                if(StrUtil.isNotEmpty(item.getOptionContentStr())){
                    item.setOptionContent(Arrays.asList(item.getOptionContentStr().split(",")));
                }
                if(StrUtil.isNotEmpty(item.getErrorOptionStr())){
                    item.setErrorOption(Arrays.asList(item.getErrorOptionStr().split(",")));
                }
            });
            return ConversionUtil.conversionList(list,InsTaskItemVO.class);
        }
        return null;
    }


    @Override
    public List<TaskItemVo> listByTaskId(Long id) {
        List<TaskItemVo> list = insTaskItemMapper.listByTaskId(id);
        return ConversionUtil.conversionList(list,TaskItemVo.class);
    }
}
